@echo off
REM 设置代码页为UTF-8
chcp 65001 >nul 2>&1
title Red Wine Sales Management System
color 0A
echo.
echo =========================================
echo       Red Wine Sales Management System
echo =========================================
echo.
cd /d "%~dp0"

REM Check Java environment
java -version >nul 2>&1
if %errorlevel% neq 0 (
    echo Error: Java environment not found, please install Java first!
    pause
    exit /b 1
)

echo [1/4] Generating source file list...
dir /b /s src\*.java > sources.txt

echo [2/4] Creating output directory...
if not exist bin mkdir bin

echo [3/4] Compiling Java files...
javac -encoding UTF-8 -d bin -cp lib/* @sources.txt

if %errorlevel% equ 0 (
    echo [4/4] Compilation successful! Starting program...
    echo.
    echo =========================================
    java -cp "bin;lib/*" App
) else (
    echo.
    echo =========================================
    echo Compilation failed! Please check code errors.
    echo =========================================
    pause
)

REM Clean temporary files
if exist sources.txt del sources.txt
echo.
echo Program exited, press any key to close window...
pause >nul
